/**
 * Copyright Quickoffice, Inc, 2005-2011
 * 
 * NOTICE: The intellectual and technical concepts contained herein are proprietary to Quickoffice, Inc. and is
 * protected by trade secret and copyright law. Dissemination of any of this information or reproduction of this
 * material is strictly forbidden unless prior written permission is obtained from Quickoffice, Inc.
 * 
 * Created: Apr 17, 2011 Author: jimmy.zhang
 * 
 */

package org.jimmy.test.sample;

import java.util.Properties;

import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3Client;

/**
 * @author jimmy.zhang
 * 
 */
public class FileStorageS3
{
	/**
	 * 
	 */
	private static final String S3_BUCKET_NAME = "s3_bucketName";

	/**
	 * 
	 */
	public static final String S3_SECRET_KEY = "s3_secretKey";

	/**
	 * 
	 */
	public static final String S3_ACCESS_KEY = "s3_accessKey";

	private final AmazonS3Client s3;


	public FileStorageS3()
	{
		this(System.getProperties());
	}


	/**
	 * 
	 */
	public FileStorageS3(Properties properties)
	{
		this(retrieveAccessKey(properties), retrieveSecretKey(properties));
	}


	/**
	 * @param accessKey
	 * @param secretKey
	 */
	public FileStorageS3(String accessKey, String secretKey)
	{
		if ( null == accessKey )
		{
			throw new NullPointerException("accessKey can not be null");
		}

		if ( null == secretKey )
		{
			throw new NullPointerException("secretKey can not be null");
		}

		s3 = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey));
	}


	public static String retrieveAccessKey(Properties properties)
	{
		return properties.getProperty(S3_ACCESS_KEY);
	}


	public static String retrieveSecretKey(Properties properties)
	{
		return properties.getProperty(S3_SECRET_KEY);
	}


	public static String retrieveBucketName(Properties properties)
	{
		return properties.getProperty(S3_BUCKET_NAME);
	}


	/**
	 * @return the s3
	 */
	public final AmazonS3Client getS3Cient()
	{
		return s3;
	}

}
